package com.hzsd.zengbanyi.biaodan_text.Actrivity;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hzsd.zengbanyi.biaodan_text.BaseActivity;
import com.hzsd.zengbanyi.biaodan_text.R;
import com.hzsd.zengbanyi.biaodan_text.bean.MediaBean;
import com.hzsd.zengbanyi.biaodan_text.bean.Signature;

import java.io.File;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;


public class MainActivity extends BaseActivity {
    private String name, group, userId, urlPath, uploadPath;
    private String DownLoadUrl;
    private String currentPath;
    private String source;
    private String fileName;
    private ProgressDialog selectorDialog;
    private AlertDialog.Builder alertDialog;
    private ArrayList<MediaBean> mediaList;
    private ArrayList<Signature> signatureList;
    private TextView textUser, textOut;
    private RelativeLayout rlPlan, rl_environmentalQuality, rldownload,
            rlupload, rlLhs, rlFlow, rlSjjh;
    int Error = 0;
    private int mediaIndex = 0;
    private int signIndex = 0;

    private Timer timer;
    private TimerTask timerTask;
    /***
     * 定时器时间间隔
     */
    public long Interval = 1000;
    /***
     * 进度
     */
    private int Schedule = 0;

    private long exitTime;

    public static String FileFolder = "hzzc";// 一级目录
    private final static String File_PATH = Environment
            .getExternalStorageDirectory()
            + File.separator
            + FileFolder
            + File.separator;

    private static final int HANDLER_TOLEAD_PLAN = 1;
    private static final int HANDLER_UP_DATABASE = 2;
    private static final int HANDLER_UP_IMG = 3;

    private static final int DIALOG_PROGRESS = 1;
    private static final int DIALOG_HORIZONTAL = 2;
    /***
     * 进度标识
     */
    private static final int HANDLER_DOW_PROGRESS = 4;
    String UploadResult = "";


    protected Dialog onCreateDialog(int id, Bundle bundle) {
        Dialog dialog = null;

        switch (id) {
            case DIALOG_PROGRESS:
                dialog = new ProgressDialog(this);
                ((ProgressDialog) dialog)
                        .setProgressStyle(ProgressDialog.STYLE_SPINNER);// 设置进度条的形式为圆形转动的进度条
                dialog.setCancelable(true);// 设置是否可以通过点击Back键取消
                dialog.setCanceledOnTouchOutside(false);// 设置在点击Dialog外是否取消Dialog进度条
                dialog.show();
                break;
            case DIALOG_HORIZONTAL:
                dialog = new ProgressDialog(this);
                ((ProgressDialog) dialog)
                        .setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);// 设置进度条的形式为条形的进度条
                dialog.setCancelable(true);// 设置是否可以通过点击Back键取消
                dialog.setCanceledOnTouchOutside(false);// 设置在点击Dialog外是否取消Dialog进度条
                ((ProgressDialog) dialog).setMessage("正在导入项目计划...");
                ((ProgressDialog) dialog).setProgress(0);
                dialog.show();
                break;

        }
        return dialog;
    }

    ;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main1);
        initDate();
        initView();

    }

    private void initDate() {
        SharedPreferences share = getSharedPreferences("user", MODE_PRIVATE);
        group = share.getString("group", "");
        name = share.getString("name", "");
        userId = share.getString("userId", "");
        urlPath = share.getString("urlPath", "");
        uploadPath = share.getString("upLoadurlPath", "");

    }

    private void initView() {
        textUser = (TextView) findViewById(R.id.tv_userinfo);
        textOut = (TextView) findViewById(R.id.outoff);
//        rlPlan = (RelativeLayout) findViewById(R.id.planed);
//        rl_environmentalQuality = (RelativeLayout) findViewById(R.id.rl_environmentalQuality);
//        rldownload = (RelativeLayout) findViewById(R.id.rldownload);
//        rlFlow = (RelativeLayout) findViewById(R.id.sample_flow);
        rlLhs = (RelativeLayout) findViewById(R.id.sample_lhs);
        rlSjjh = (RelativeLayout) findViewById(R.id.sample_sjjh);
//        rlupload = (RelativeLayout) findViewById(R.id.rlupload);
        textUser.setText(name + '/' + group);
        /*
		 * selectorDialog = new ProgressDialog(this);
		 * selectorDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);//
		 * 设置进度条的形式为圆形转动的进度条 selectorDialog.setCancelable(true);//
		 * 设置是否可以通过点击Back键取消 selectorDialog.setCanceledOnTouchOutside(false);//
		 * 设置在点击Dialog外是否取消Dialog进度条
		 */
        // alertDialog = new AlertDialog.Builder(this);
        // alertDialog.setTitle("提醒");
        // alertDialog.setMessage("计划项目上传完成");
        // alertDialog.setNegativeButton("确定", null);
        /**
         * 理化室
         */
        rlLhs.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
//				Intent intent = new Intent(MainActivity.this, WebActivity.class);
                Intent intent = new Intent(MainActivity.this, LabActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("title", "理化室");
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });

        /**
         * 数据校核
         */
        rlSjjh.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {


                Intent intent = new Intent(MainActivity.this, WebActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("title", "数据校核");
                intent.putExtras(bundle);
                startActivity(intent);


            }
        });



    }


}
